package com.fanxuankai.boot.upload.handler;

import com.fanxuankai.boot.upload.EasyExcelReader;
import com.fanxuankai.boot.upload.Reader;
import com.fanxuankai.boot.upload.UploadHandler;
import com.fanxuankai.boot.upload.dao.UserDao;
import com.fanxuankai.boot.upload.domain.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author fanxuankai
 */
@Slf4j
@Component
public class UserUploadHandler implements UploadHandler<User, User> {
    @Resource
    private UserDao userDao;

    @Override
    public Reader<User> reader() {
        return new EasyExcelReader<>();
    }

    @Override
    public User process(User item) {
        return item;
    }

    @Override
    public void write(List<User> items) {
        userDao.saveBatch(items);
    }
}
